package zy.blue7.im.handler.impl;

import io.netty.channel.Channel;
import zy.blue7.im.common.message.GroupMessage;
import zy.blue7.im.common.message.Message;
import zy.blue7.im.common.message.SingleMessage;
import zy.blue7.im.handler.ClientMessageHandler;

import javax.swing.*;
import java.awt.*;

/**
 * @author blue7
 * @version 1.0
 * @date 2022/3/4 16:00
 */
public class GroupMessageHandlerImpl implements ClientMessageHandler {
    @Override
    public void handle(Channel channel, Message message, Container container) {
        GroupMessage groupMessage = (GroupMessage) message;
        String from = groupMessage.getFrom();
        String content = groupMessage.getContent();
        if (null == container) return;


        JTextArea jTextArea = (JTextArea) container;

        String text = jTextArea.getText();

        if (null != text && !text.trim().equalsIgnoreCase(""))
            jTextArea.setText(text + "\r\n" + from + ": " + content);
        else jTextArea.setText(from + ": " + content);
    }
}
